package com.aaa.controller;

import com.aaa.entity.User;
import com.aaa.service.UserService;
import com.aaa.vo.LoginVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年11月15日9:33
 */
@RestController
@RequestMapping("/user")
@Api(tags = "增删改查")
public class HelloController {
//    @GetMapping("/hello")
//    public Map<String,Object> hello(){
//        HashMap<String, Object> map = new HashMap<>();
//        map.put("name","张三");
//        map.put("age",20);
//        return map;
//    }
//
//    @Autowired
//    private AliPay aliPay;
//    @GetMapping("/index")
//    public AliPay index(){
//        return aliPay;
//    }

//    @Value("${server.port}")
//    private Integer port;
//
//    @Value("${student.name}")
//    private String name;
//
    @Autowired
    private UserService userService;


    @ApiOperation(value = "查所有")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "current",value = "当前页码" , defaultValue = "1" , required = false ,dataType = "int"),
                    @ApiImplicitParam(name = "pagesize",value = "每页显示的数据量" , defaultValue = "5" , required = false ,dataType = "int")
            }
    )
    @GetMapping("/userList")
    public Result userList(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "5") Integer pagesize){
        return userService.findAll(current,pagesize);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加")
    public Result add(@RequestBody User user){
        return userService.add(user);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改")
    public Result update(@RequestBody User user){
        return userService.update(user);
    }

    @DeleteMapping("/del")
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id")
    public Result del(Integer id){
        return userService.del(id);
    }


    @PostMapping("/login")
    @ApiOperation(value = "登录")
    public Result login(@RequestBody LoginVo loginVo){
        return userService.findByNameAndPassword(loginVo.getUsername(),loginVo.getPassword());

    }



}
